<?php
/**
 * 周舟 hzboye010@163.com
 * addby sublime snippets
 * 设备 测试类
 */
namespace app\test\controller;

use app\test\controller\Ava;
use app\utils\BoyeService;

class Aq extends Ava{
    //设备添加
    public function add(){
        if(IS_AJAX){
            $data = [
            'uid'          => I('post.uid',''),
            'did'          => I('post.did',''),
            'name'         => I('post.name',''),
            'token'        => I('post.token',''),
            'device_model' => I('post.device_model',''),
            'api_ver'      =>$this->api_ver,
            'notify_id'    =>$this->notify_id,
            'alg'          =>$this->alg,
            'type'         =>'BY_Aq_add',
          ];

          $service = new BoyeService();
          $result  = $service->callRemote("",$data,true);
          echo $this->parseResult($result);
        }else{
            $this->assign('type','BY_Aq_add');
            $this->assign('field',[
                ['api_ver','100',LL('need-mark api version')],
                ['uid','42',LL('need-mark user ID')],
                ['did','SSAQ-002020-NEBDX',LL('need-mark device ID')],
                ['name','rainbow',LL('need-mark name')],
                ['token','123456',LL('need-mark token')],
                ['device_model','设备号',LL('need-mark device_model')],
            ]);
            echo $this->display('ava/test');
        }
    }

    //设备修改
    public function update(){
        if(IS_AJAX){
            $data = [
            'uid'               => I('post.uid',''),
            'id'                => I('post.id',''),
            'did'               => I('post.did',''),
            'name'              => I('post.name',''),
            'token'             => I('post.token',''),
            'device_model'      => I('post.device_model',''),
            'is_load_on'        => I('post.is_load_on',''),
            'is_level_on'       => I('post.is_level_on',''),
            'is_temperature_on' => I('post.is_temperature_on',''),
            'api_ver'      =>$this->api_ver,
            'notify_id'    =>$this->notify_id,
            'alg'          =>$this->alg,
            'type'         =>'BY_Aq_update',
          ];

          $service = new BoyeService();
          $result  = $service->callRemote("",$data,true);
          echo $this->parseResult($result);
        }else{
            $this->assign('type','BY_Aq_update');
            $this->assign('field',[
                ['api_ver','100',LL('need-mark api version')],
                ['uid','42',LL('need-mark user ID')],
                ['id','215',LL('need-mark device ID')],
                ['did','SSAQ-002020-NEBDX',LL('device ID')],
                ['name','rainbow',LL('name')],
                ['token','123456',LL('token')],
                ['device_model','设备号',LL('device_model')],
                ['is_load_on','',LL('token')],
                ['is_level_on','',LL('token')],
                ['is_temperature_on','',LL('token')],
            ]);
            echo $this->display('ava/test');
        }
    }

    //设备删除
    public function delete(){
        if(IS_AJAX){
            $data = [
            'uid'       => I('post.uid',''),
            'id'        => I('post.id',''),
            'api_ver'   =>$this->api_ver,
            'notify_id' =>$this->notify_id,
            'alg'       =>$this->alg,
            'type'      =>'BY_Aq_delete',
          ];

          $service = new BoyeService();
          $result  = $service->callRemote("",$data,true);
          echo $this->parseResult($result);
        }else{
            $this->assign('type','BY_Aq_delete');
            $this->assign('field',[
                ['api_ver','100',LL('need-mark api version')],
                ['uid','42',LL('need-mark user ID')],
                ['id','215',LL('need-mark device ID')],
            ]);
            echo $this->display('ava/test');
        }
    }

    //设备查询
    public function query(){
        if(IS_AJAX){
            $data = [
            'uid'       => I('post.uid',''),
            'api_ver'   =>$this->api_ver,
            'notify_id' =>$this->notify_id,
            'alg'       =>$this->alg,
            'type'      =>'BY_Aq_query',
          ];

          $service = new BoyeService();
          $result  = $service->callRemote("",$data,true);
          echo $this->parseResult($result);
        }else{
            $this->assign('type','BY_Aq_query');
            $this->assign('field',[
                ['api_ver','100',LL('need-mark api version')],
                ['uid','42',LL('need-mark user ID')],
            ]);
            echo $this->display('ava/test');
        }
    }
}